package com.guldan.thrall.web.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.guldan.core.controller.BaseController;
import com.guldan.core.dubbo.client.ResponseDTO;
import com.guldan.core.response.ResponseJson;
import com.guldan.jaina.dto.projecttag.ProjectTagDTO;
import com.guldan.jaina.dto.projecttag.ProjectTagSearchDTO;
import com.guldan.jaina.provider.IProjectProvider;

/**
 * Created by Silas.
 * Date: 2016/11/10
 * Time: 22:06
 */
@Controller
@RequestMapping("/projectTag")
public class ProjectTagController extends BaseController {


    @Autowired
    private IProjectProvider iProjectProvider;

    //获取单个项目标签
    @RequestMapping(value = "/get", method = RequestMethod.POST)
    @ResponseJson
    public
    @ResponseBody
    ProjectTagDTO get(@RequestBody ProjectTagDTO dto) {
        ResponseDTO<ProjectTagDTO> response = iProjectProvider.getProjectTag(dto.getProjectTagId());
        return response.getData();
    }

    //新增/保存单个项目标签
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @ResponseJson
    public
    @ResponseBody
    ProjectTagDTO save(@RequestBody ProjectTagDTO dto) throws Exception {
        ResponseDTO<ProjectTagDTO> response = iProjectProvider.saveProjectTag(dto);
        if (response.isSuccess())
            return response.getData();
        else {
            throw response.getException();
        }
    }

    //删除单个项目标签
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @ResponseJson
    public
    @ResponseBody
    Boolean delete(@RequestBody ProjectTagDTO dto) {
        ResponseDTO<Boolean> response = iProjectProvider.deleteProjectTag(dto.getProjectTagId());
        return response.getData();
    }

    //获取项目标签列表
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ResponseJson
    public
    @ResponseBody
    List<ProjectTagDTO> list() {
    	ProjectTagSearchDTO dto = new ProjectTagSearchDTO();
    	ResponseDTO<List<ProjectTagDTO>> response = iProjectProvider.allProjectTag(dto);
        return response.getData();
    }


}
